import request from '@/utils/request'
const url = 'http://10.2.1.130:8130/steel_pmo/company'
export default class Company {
    constructor() {

    }
    pageObj(data: any) {
        return request.post({
            url: `${url}/pageObj`,

            data
        })
    }
    count4Page(data: any) {
        return request.post({
            url: `${url}/count4Page`,

            data
        })
    }
    createObj(data: any): any {
        return request.post({
            url: `${url}/createObj`,

            data: this.format(data)
        })
    }
    getObjById(data: any): any {
        return request.post({
            url: `${url}/getObjById`,

            data
        })
    }

    updateObj(data: any): any {
        return request.post({
            url: `${url}/updateObj`,

            data: this.format(data)
        })
    }

    listObj(data: any): any {
        return request.post({
            url: `${url}/listObj`,

            data
        })
    }

    deleteObj(data: any): any {
        const ID = this.getKey(data)
        return request.post({
            url: `${url}/deleteObj`,

            data: { ID }
        })
    }

    deleteObjs(data: any): any {
        return request.post({
            url: `${url}/deleteObjs`,

            data
        })
    }

    getDesc(obj: any): any {
        return obj.Name
    }
    getKey(obj: any): any {
        return "" + obj.Token
    }
    getDescField(): any {
        return 'Name'
    }
    getKeyField(obj: any): any {
        return ["Token"]
    }
    format(obj: any): any {
        if (null !== obj.AnnualProduction && undefined !== obj.AnnualProduction) {
            obj.AnnualProduction = parseFloat("" + obj.AnnualProduction)
        }
        return obj
    }
    format4Select(obj: any): any {
        return obj
    }
    // 字段的名称
    fields = [
        {
            title: '名称',
            dataIndex: 'Name',
            key: 'company.name',
            query: true,
            sorter: true
        },
        {
            title: '计划年产量',
            dataIndex: 'AnnualProduction',
            key: 'company.annual_production',
            query: true,
            sorter: true
        }
    ]
}
